<template>
  <div class="layout-container">
    <div class="sidebar">
      <div class="logo">再生道环保管理系统</div>
      <el-menu
        :default-active="activeMenu"
        class="menu-list"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
        router
      >
        <el-menu-item index="/platform/orders">
          <i class="el-icon-s-order"></i>
          <span slot="title">回收站工作台</span>
        </el-menu-item>
        <el-menu-item index="/platform/announcement">
          <i class="el-icon-bell"></i>
          <span slot="title">公告管理</span>
        </el-menu-item>
        <el-menu-item index="/platform/permission">
          <i class="el-icon-lock"></i>
          <span slot="title">权限管理</span>
        </el-menu-item>
        <el-menu-item index="/platform/stations">
          <i class="el-icon-location"></i>
          <span slot="title">站点管理</span>
        </el-menu-item>
        <el-menu-item index="/platform/material">
          <i class="el-icon-delete"></i>
          <span slot="title">物料管理</span>
        </el-menu-item>
      </el-menu>
    </div>
    <div class="main-content">
      <div class="header-bar">
        <div class="left-section">
          <i class="el-icon-s-fold toggle-sidebar" @click="toggleSidebar"></i>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/platform' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ currentPageTitle }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="right-section">
          <el-dropdown trigger="click" @command="handleCommand">
            <span class="user-dropdown">
              <i class="el-icon-user"></i>
              管理员
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="profile">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
      <div class="content-area">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PlatformLayout',
  data() {
    return {
      isCollapse: false,
      menuItems: [
        { title: '回收站工作台', path: '/platform/orders', icon: 'el-icon-s-order' },
        { title: '公告管理', path: '/platform/announcement', icon: 'el-icon-bell' },
        { title: '权限管理', path: '/platform/permission', icon: 'el-icon-lock' },
        { title: '积分商城', path: '/#', icon: 'el-icon-shopping-cart-full' },
        { title: '系统管理', path: '/#', icon: 'el-icon-setting' }
      ]
    }
  },
  computed: {
    activeMenu() {
      return this.$route.path
    },
    currentPageTitle() {
      const currentRoute = this.menuItems.find(item => this.$route.path.includes(item.path))
      return currentRoute ? currentRoute.title : '管理平台'
    }
  },
  methods: {
    toggleSidebar() {
      this.isCollapse = !this.isCollapse
    },
    handleCommand(command) {
      if (command === 'logout') {
        this.$confirm('确认退出系统?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          localStorage.removeItem('adminToken')
          localStorage.removeItem('adminId')
          this.$router.push('/platform/login')
          this.$message.success('已退出登录')
        }).catch(() => {})
      } else if (command === 'profile') {
        this.$router.push('/platform/profile')
      }
    }
  }
}
</script>

<style scoped>
.layout-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  background-color: #304156;
  color: white;
  transition: width 0.3s;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar.collapsed {
  width: 64px;
}

.logo {
  height: 60px;
  line-height: 60px;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: white;
  background-color: #263445;
  overflow: hidden;
  white-space: nowrap;
}

.menu-list {
  border-right: none;
  height: calc(100vh - 60px);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header-bar {
  height: 60px;
  background-color: white;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.left-section {
  display: flex;
  align-items: center;
}

.toggle-sidebar {
  font-size: 20px;
  margin-right: 20px;
  cursor: pointer;
}

.user-dropdown {
  cursor: pointer;
  color: #606266;
  display: flex;
  align-items: center;
  gap: 5px;
}

.content-area {
  flex: 1;
  padding: 20px;
  background-color: #f0f2f5;
  overflow-y: auto;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    z-index: 10;
    height: 100%;
    transform: translateX(0);
    transition: transform 0.3s;
  }
  
  .sidebar.collapsed {
    transform: translateX(-100%);
  }
  
  .main-content {
    margin-left: 0;
  }
}
</style> 